﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lion.WeiXin.Core.Data;
namespace Lion.WeiXin.Core
{
    /// <summary>
    /// 模板引擎数据实体
    /// </summary>
   public class TemplateEngineModel
    {

  
       DBContext db = new DBContext();
       /// <summary>
       /// 当前文章对象（适合文章模板）
       /// </summary>
       public Models.ArticleModel Article { get; set; }

       /// <summary>
       /// 当前栏目对象 (适合栏目模板）
       /// </summary>
       public Models.CategoryModel Category { get; set; }

       /// <summary>
       /// 获取指定栏目文章列表 （适合任意模板）
       /// </summary>
       /// <param name="count">获取文章记录数</param>
       /// <param name="categoryId">栏目分类Id</param>
       /// <returns></returns>
       public List<Models.ArticleModel> GetArticleList(int count, string categoryId)
       {
           return db.Articles.GetList(count, "CategoryID=" + categoryId, "AID DESC");
       }
       /// <summary>
       /// 获取当前栏目文章列表(适合栏目模板）
       /// </summary>
       /// <param name="count"></param>
       /// <returns></returns>
       public List<Models.ArticleModel> GetArticleList(int count)
       {
           if (Category == null)
           {
               return new List<Models.ArticleModel>();
           }

           return db.Articles.GetList(count, "CategoryID=" + this.Category.AID, "AID DESC");
       }

       /// <summary>
       /// 获取首页导航栏目条 ( 
       /// </summary>
       /// <returns></returns>
       public List<Models.CategoryModel> GetHomeNav()
       {
           return db.Categorys.GetList(100,"IsShow=1","Sort");
       }

       /// <summary>
       /// 获取固定数量最新产品
       /// </summary>
       /// <param name="count"></param>
       /// <returns></returns>
       public List<Models.ProductModel> GetProducts(int count)
       {
           return db.Products.GetList(count, "", "AID DESC");
       }
       /// <summary>
       /// 获取指定类型产品
       /// </summary>
       /// <param name="count">获取数量</param>
       /// <param name="typeId">类型ID</param>
       /// <returns></returns>
       public List<Models.ProductModel> GetProducts(int count, int typeId)
       {
           return db.Products.GetList(count, "Dic_ProductType="+typeId.ToString(), "AID DESC");
       }

       /// <summary>
       /// 获取热销产品
       /// </summary>
       /// <param name="count"></param>
       /// <returns></returns>
       public List<Models.ProductModel> GetHotProducts(int count)
       {
           return db.Products.GetList(count, "", "sale DESC");
       }
    }
}
